package cn.imnaer.service.rest.view.model;

import java.util.ArrayList;
import java.util.List;

import cn.imnaer.service.Interceptor.CommonInterceptor;
import cn.imnaer.service.persistence.model.FriendRelation;
import cn.imnaer.service.persistence.model.TravelNote;
import cn.imnaer.service.persistence.model.TravelNotePhoto;
import cn.imnaer.service.persistence.model.TribalMessage;
import cn.imnaer.service.rest.resquest.model.TribalCircleCreateParams;

import com.fasterxml.jackson.annotation.JsonIgnore;

public class TravelNoteDetail implements CommonInterceptor {
	private String travelNoteId;
	private String travelNoteName;
	private String userId;
	private String userName;
	private int dayCount;
	private int placeCount;
	private String cityCode;
	private String placeType;

	private String  cityName;
	private String tag;
	private String monthIndex;
	private String money;
	private String tips;
	private List<TravelNotePhotoDetail> travelNotePhotos;
	private int collectCount; // 收藏只能收藏整个游记
	@JsonIgnore
	private int supportCount;
	private int commentCount;
	private long createTime;
	private boolean isCollected;
	private boolean isShared;
    private List<TribalCircleCreateParams> tribalParams = new ArrayList<>();
    private List<TribalCircleCreateParams> tribalCircleCreateItems = new ArrayList<>();
	public String getCityCode() {
		return cityCode;
	}

	public void setCityCode(String cityCode) {
		this.cityCode = cityCode;
	}

	public String getPlaceType() {
		return placeType;
	}

	public void setPlaceType(String placeType) {
		this.placeType = placeType;
	}





	public boolean getIsCollected() {
		return isCollected;
	}

	public void setIsCollected(boolean isCollected) {
		this.isCollected = isCollected;
	}
	public boolean getIsShared() {
		return isShared;
	}

	public void setIsShared(boolean isShare) {
		this.isShared = isShare;
	}

	public String getTravelNoteId() {
		return travelNoteId;
	}

	public void setTravelNoteId(String travelNoteId) {
		this.travelNoteId = travelNoteId;
	}

	public String getTravelNoteName() {
		return travelNoteName;
	}

	public void setTravelNoteName(String travelNoteName) {
		this.travelNoteName = travelNoteName;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public int getDayCount() {
		return dayCount;
	}

	public void setDayCount(int dayCount) {
		this.dayCount = dayCount;
	}

	public int getPlaceCount() {
		return placeCount;
	}

	public void setPlaceCount(int placeCount) {
		this.placeCount = placeCount;
	}



	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public String getMonthIndex() {
		return monthIndex;
	}

	public void setMonthIndex(String monthIndex) {
		this.monthIndex = monthIndex;
	}

	public String getMoney() {
		return money;
	}

	public void setMoney(String money) {
		this.money = money;
	}

	public String getTips() {
		return tips;
	}

	public void setTips(String tips) {
		this.tips = tips;
	}

	public List<TravelNotePhotoDetail> getTravelNotePhotos() {
		return travelNotePhotos;
	}

	public void setTravelNotePhotos(List<TravelNotePhotoDetail> travelNotePhotos) {
		this.travelNotePhotos = travelNotePhotos;
	}

	public int getCollectCount() {
		return collectCount;
	}

	public void setCollectCount(int collectCount) {
		this.collectCount = collectCount;
	}

	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}



	public int getSupportCount() {
		return supportCount;
	}

	public void setSupportCount(int supportCount) {
		this.supportCount = supportCount;
	}

	public int getCommentCount() {
		return commentCount;
	}

	public void setCommentCount(int commentCount) {
		this.commentCount = commentCount;
	}

    public List<TribalCircleCreateParams> getTribalParams() {
        return tribalParams;
    }


    public void setTribalCircleCreateItems(List<TribalCircleCreateParams> tribalCircleCreateItems) {
        this.tribalCircleCreateItems = tribalCircleCreateItems;
    }
	public String getCityName() {
		return cityName;
	}
	public void setCityName(String cityName) {
		this.cityName = cityName;
	}

    public TravelNote buildTravelNote() {
		TravelNote travelNote = new TravelNote();
		travelNote.setTravelNoteName(this.travelNoteName);
		travelNote.setUserId(this.userId);
		travelNote.setIsShared(this.isShared);
		travelNote.setUserId(this.userId);
		travelNote.setDayCount(this.dayCount);
		travelNote.setMoney(this.money);
		travelNote.setMonthIndex(this.monthIndex);
		ArrayList<String> tags = new ArrayList<String>(1);
		if(this.tag!=null){
		tags.add(this.tag);
		}
		travelNote.setTag(tags);
		travelNote.setTips(this.tips);
		travelNote.setCityCode(this.cityCode);
		travelNote.setCityName(this.cityName);
		travelNote.setPlaceCount(this.placeCount);
		List<TravelNotePhotoDetail> travelNotePhotoDetails = this.travelNotePhotos;
		List<TravelNotePhoto> travelNotePhotos = new ArrayList<TravelNotePhoto>(travelNotePhotoDetails.size());
		for (TravelNotePhotoDetail travelNotePhotoDetail : travelNotePhotoDetails) {
			TravelNotePhoto travelNotePhoto = travelNotePhotoDetail.buildTravelNotePhoto();
			travelNotePhotos.add(travelNotePhoto);
		}
		travelNote.setTravelNotePhotos(travelNotePhotos);
		return travelNote;
	}

	public static TravelNoteDetail valueOf(TravelNote travelNote) {
		TravelNoteDetail travelNoteDetail = new TravelNoteDetail();
		travelNoteDetail.setTravelNoteId(travelNote.getTravelNoteId());
		travelNoteDetail.setTravelNoteName(travelNote.getTravelNoteName());
		travelNoteDetail.setUserId(travelNote.getUserId());
		travelNoteDetail.setIsShared(travelNote.getIsShared());
		travelNoteDetail.setUserId(travelNote.getUserId());
		travelNoteDetail.setDayCount(travelNote.getDayCount());
		travelNoteDetail.setPlaceCount(travelNote.getPlaceCount());
		travelNoteDetail.setMoney(travelNote.getMoney());
		travelNoteDetail.setMonthIndex(travelNote.getMonthIndex());
		if(travelNote.getTag()!=null&&travelNote.getTag().size()>0){
			if(travelNote.getTag().get(0)!=null)
			travelNoteDetail.setTag(travelNote.getTag().get(0));
		}
		travelNoteDetail.setTips(travelNote.getTips());
		travelNoteDetail.setCityCode(travelNote.getCityCode());
		travelNoteDetail.setCityName(travelNote.getCityName());
		travelNoteDetail.setCreateTime(travelNote.getCreateTime());
		travelNoteDetail.setCollectCount(travelNote.getCollectCount());
		List<TravelNotePhoto> travelNotePhotos = travelNote.getTravelNotePhotos();
		List<TravelNotePhotoDetail> travelNotePhotoDetails = new ArrayList<TravelNotePhotoDetail>(
				travelNotePhotos.size());
		for (TravelNotePhoto travelNotePhoto : travelNotePhotos) {
			TravelNotePhotoDetail travelNotePhotoDetail = TravelNotePhotoDetail.valueOf(travelNotePhoto);
			travelNotePhotoDetails.add(travelNotePhotoDetail);

		}

		travelNoteDetail.setTravelNotePhotos(travelNotePhotoDetails);
		return travelNoteDetail;
	}

	@Override
	public void supportInterceptor(List<String> hasPermissionUsers) {

	}

	@Override
	public void collectInterceptor(List<String> collectList) {
		if (collectList.contains(this.travelNoteId)) {
			this.setIsCollected(true);
		}

	}

	@Override
	public void userNameInterceptor(List<FriendRelation> friendRelations) {
		if (friendRelations != null) {
			for (FriendRelation friendRelation : friendRelations) {
				if (friendRelation.getFriendUserId().equals(userId)) {
					this.setUserName(friendRelation.getNote());
				}
			}
		}
	}
}
